package com.eonmind.vip.controller;

import com.eonmind.common.contract.data.response.PageResponse;
import com.eonmind.common.contract.data.response.ResponseEntity;
import com.eonmind.common.provider.entity.vip.PointsConsumption;
import com.eonmind.common.security.annotations.UserInfo;
import com.eonmind.user.contract.dto.UserInfoData;
import com.eonmind.vip.dto.ConsumptionDto;
import com.eonmind.vip.service.PointsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 积分相关
 */
@RestController
@RequestMapping("/points")
public class PointsController {

    @Autowired
    private PointsService pointsService;

    /**
     * 保存积分消费记录
     * @return ResponseEntity<Integer>
     * @ignoreParams userInfoData
     */
    @PostMapping("/savePointsConsumption")
    @UserInfo
    public ResponseEntity<Boolean> saveConsumption(@RequestBody PointsConsumption pointsConsumption, UserInfoData userInfoData) {
        pointsService.savePointsConsumption(pointsConsumption, userInfoData);
        return ResponseEntity.success(true);
    }
    /**
     * 分页查询消费
     *
     * @param pageRequest 请求参数
     * @return
     * @ignoreParams userInfoData
     */
    @PostMapping("/getPointsConsumption")
    @UserInfo
    public ResponseEntity<PageResponse<ConsumptionDto.ConsumptionResponse>> getConsumption(UserInfoData userInfoData, @RequestBody ConsumptionDto.ConsumptionPageRequest pageRequest) {
        return ResponseEntity.success(pointsService.getAllConsumption(userInfoData, pageRequest));
    }

    /**
     * 获取近五个月的消费数据
     *
     * @param pageRequest 请求参数
     * @return
     * @ignoreParams userInfoData
     */
    @GetMapping("/getMonthConsumption")
    @UserInfo
    public ResponseEntity<List<ConsumptionDto.MonthConsumption>> getConsumption(UserInfoData userInfoData) {
        return ResponseEntity.success(pointsService.getMonthConsumption(userInfoData));
    }


}
